package ch14.memcached;

import net.rubyeye.xmemcached.command.binary.OpCode;

import java.util.Random;

/**
 * Created by zc on 2016/6/8.
 */
public class MemcachedRequest {
    private static final Random rand = new Random();

    private int magic = 0x80;
    private byte opCode;
    private String key;
    private int flags = 0;
    private int expires;
    private String body;
    private int id = rand.nextInt();
    private long cas;
    private boolean hasExtras;

    public MemcachedRequest(byte opCode, String key, String value) {
        this.opCode = opCode;
        this.key = key;
        this.hasExtras = (opCode == Opcode.SET);
        this.body = value == null ? "" : value;
    }

    public MemcachedRequest(byte opCode, String key) {
        this(opCode,key,null);
    }

    public static Random getRand() {
        return rand;
    }

    public int getMagic() {
        return magic;
    }

    public void setMagic(int magic) {
        this.magic = magic;
    }

    public byte getOpCode() {
        return opCode;
    }

    public void setOpCode(byte opCode) {
        this.opCode = opCode;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public int getFlags() {
        return flags;
    }

    public void setFlags(int flags) {
        this.flags = flags;
    }

    public int getExpires() {
        return expires;
    }

    public void setExpires(int expires) {
        this.expires = expires;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public long getCas() {
        return cas;
    }

    public void setCas(long cas) {
        this.cas = cas;
    }

    public boolean isHasExtras() {
        return hasExtras;
    }

    public void setHasExtras(boolean hasExtras) {
        this.hasExtras = hasExtras;
    }
}
